from amqp import channel
from django.shortcuts import render
# Create your views here.
from django.views import View

from apps.contents.models import ContentCategory
from apps.contents.utils import get_categories
from apps.goods.models import GoodsChannel
class IndexView(View):
    def get(self,request):
        #1.三级商品分类获取
        categories = get_categories()
        #2.广告数据的获取
        #2.1获取  所有  广告分类
        ad_categories = ContentCategory.objects.all()
        #2.2遍历
        contents = {}
        for ad in ad_categories:
            # 2.3 组合前端需要的数据格式--分类--广告内容content_set.filter()
            contents[ad.key]=ad.content_set.filter(status=True).order_by("sequence")
        context = {
            "categories":categories,
            "contents":contents,
        }
        return render(request, "index.html",context)
